package com.imooc.ecommerce.service.communication.hystrix;

import com.imooc.ecommerce.service.communication.AuthorityFeignClient;
import com.imooc.ecommerce.vo.JwtToken;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * <p>OpenFeign 集成 Hystrix 的另一种模式
 *
 * @author Yaxi.Zhang
 * @since 2022/11/14 20:23
 */
@Slf4j
@Component
public class AuthorityFeignClientFallbackFactory implements FallbackFactory<AuthorityFeignClient> {
    @Override
    public AuthorityFeignClient create(Throwable throwable) {
        log.warn("authority feign client get token by feign request error " +
                "(Hystrix FallbackFactory): [{}]", throwable.getMessage(), throwable);
        return usernameAndPassword -> new JwtToken("qinyi-factory");
    }
}
